package com.rules.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rules.admin.entity.RemoteModel;
import com.rules.admin.service.RemoteService;
import com.rules.admin.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping({"/remote"})
@Controller
public class RemoteController {
   @Autowired
   private RemoteService remoteService;

   @RequestMapping(
      value = {"remote_page"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public IPage<RemoteModel> queryPage(RemoteModel remoteModel, IPage<RemoteModel> page) {
      return this.remoteService.queryPage(remoteModel, page);
   }

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public Map<String, Object> addRemote(@RequestBody RemoteModel remoteModel) {
      this.remoteService.save(remoteModel);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getRemote(@PathVariable("id") String id) {
      RemoteModel remoteModel = (RemoteModel)this.remoteService.getById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData(remoteModel);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deleteRemote(@PathVariable("id") String id) {
      this.remoteService.removeById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      method = {RequestMethod.PUT}
   )
   @ResponseBody
   public Map<String, Object> updateRemote(@RequestBody RemoteModel remoteModel) {
      this.remoteService.save(remoteModel);
      return ResultUtils.getSuccessResultData();
   }
}
